package com.twu.biblioteca;

public class LibraryNumber {
    private final int NUMBER_OF_PARTS = 2;
    private int left = 0;
    private int right = 0;
    private final String SEPARATOR = "-";

    public LibraryNumber(int left, int right) {
        this.left = left;
        this.right = right;
    }

    public LibraryNumber(String number) {
        String[] split = number.split(SEPARATOR);

        if (split.length != NUMBER_OF_PARTS) throw new IllegalArgumentException();

        this.left = new Integer(split[0]);
        this.right = new Integer(split[1]);
    }

    @Override
    public String toString() {
        return this.left + SEPARATOR + this.right;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        LibraryNumber that = (LibraryNumber) o;

        if (left != that.left) return false;
        if (right != that.right) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = left;
        result = 31 * result + right;
        return result;
    }

    public LibraryNumber increment() {
        return new LibraryNumber(left, right + 1);
    }
}
